package com.indictor.bean;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class IndicatorApplicationContext {

    /**
     * 要替换成cache
     */
    private final Map<String, IndicatorCommand> commandMap = new ConcurrentHashMap<>();


    /**
     * 要替换成cache
     */
    private final Map<String, Indicator> indicatorMap = new ConcurrentHashMap<>();

    /**
     * 参数缓存
     */
    private final Map<String, BigDecimal> parameterMap = new ConcurrentHashMap<>();
    /**
     * 结果缓存
     */
    private final Map<String, Object> valueMap = new ConcurrentHashMap<>();

    private static final IndicatorApplicationContext indicatorApplicationContext = new IndicatorApplicationContext();

    public static IndicatorApplicationContext getInstance() {
        return indicatorApplicationContext;
    }

    public void put(String key, IndicatorCommand command) {
        commandMap.put(key, command);
    }

    public IndicatorCommand get(String key) {
        return commandMap.get(key);
    }

    /**
     * 清除公式缓存
     */
    public void clean() {
        this.commandMap.clear();
    }


    /**
     * 适配器
     *
     * @return
     */
    public IndicatorAdapter defaultComputeAdapter() {
        return new IndicatorAdapter(new IndicatorCommandComputer(), new DefaultIndicatorManager());
    }

    /**
     * 适配器
     *
     * @return
     */
    public IndicatorAdapter computeAdapter(IndicatorComputer commandComputer, DefaultIndicatorManager manager) {
        return new IndicatorAdapter(commandComputer, manager);
    }

    public Map<String, BigDecimal> getParameterMap() {
        return parameterMap;
    }

    public Map<String, Object> getValueMap() {
        return valueMap;
    }

    public void setValueMap(String key, Object o) {
        valueMap.put(key, o);
    }


    public void setParameterMap(String key, BigDecimal o) {
        parameterMap.put(key, o);
    }


    public Map<String, Indicator> getIndicatorMap() {
        return indicatorMap;
    }

    public void getIndicatorMap(String key, Indicator indicator) {
        indicatorMap.put(key, indicator);
    }
}
